<template>
	<view class="component">
		<!-- <view class="listItem flex" @click="adviserJoin">
			<view class="navTitle flex">
				<image class="imgBox" src="https://image.srea.org.cn/xcx/adviser.png"></image>
				<text class="left-5">置业顾问入驻</text>
			</view>
			<u-icon name="arrow-right" color="#D0CDD0" size="16"></u-icon>
		</view> -->
		<view class="listItem flex" @click="toStatisticsForm" v-if="isAdviser">
			<view class="navTitle flex">
				<u-icon name="order" class="myIcon" color="#D0CDD0" size="18"></u-icon>
				<text class="left-5">数据填写</text>
			</view>
			<u-icon name="arrow-right" color="#D0CDD0" size="16"></u-icon>
		</view>

		<view class="listItem flex" @click="toStatisticsPage" v-if="isAdmin">
			<view class="navTitle flex">
				<u-icon name="file-text" class="myIcon" color="#D0CDD0" size="18"></u-icon>
				<text class="left-5">数据查看</text>
			</view>
			<u-icon name="arrow-right" color="#D0CDD0" size="16"></u-icon>
		</view>

		<view class="listItem pushHouseBox flex">
			<view class="navTitle flex">
				<u-icon name="volume" class="myIcon" color="#D0CDD0" size="18"></u-icon>
				<text class="left-5">推送楼盘</text>
			</view>
			<switch :checked="check" @change="pushHouseChange" style="transform: scale(0.7,0.7)" color="#007235" />
		</view>

		<view class="listItem flex" @click="toFeedback">
			<view class="navTitle flex">
				<u-icon name="edit-pen" class="myIcon" color="#D0CDD0" size="18"></u-icon>
				<text class="left-5">问题反馈</text>
			</view>
			<u-icon name="arrow-right" color="#D0CDD0" size="16"></u-icon>
		</view>
		
		<view class="listItem flex" @click="toCurrency">
			<view class="navTitle flex">
				<u-icon name="setting" class="myIcon" color="#D0CDD0" size="18"></u-icon>
				<text class="left-5">通用设置</text>
			</view>
			<u-icon name="arrow-right" color="#D0CDD0" size="16"></u-icon>
		</view>
		
		<view class="listItem flex" @click="toAgreement">
			<view class="navTitle flex">
				<u-icon name="attach" class="myIcon" color="#D0CDD0" size="18"></u-icon>
				<text class="left-5">用户服务协议</text>
			</view>
			<u-icon name="arrow-right" color="#D0CDD0" size="16"></u-icon>
		</view>
		<view class="listItem flex" @click="toPolicy">
			<view class="navTitle flex">
				<u-icon name="attach" class="myIcon" color="#D0CDD0" size="18"></u-icon>
				<text class="left-5">隐私政策</text>
			</view>
			<u-icon name="arrow-right" color="#D0CDD0" size="16"></u-icon>
		</view>
	</view>
</template>

<script setup>
	import { computed } from 'vue';
	import { storeToRefs } from 'pinia';
	import { useIndexStore, useUserInfoStore } from '@/store/index';
    import { checkLogin, checkWXPrivacyAuthorize, savePhotoAuth, checkUserInfo } from '@/common/common';
	import { pushHouseMsg } from '@/common/api';
	import { openAgreement, openPolicy } from '@/common/utils/docts';

	const indexStore = useIndexStore();
	const userInfoStore = useUserInfoStore();
	const { adviserId } = storeToRefs(indexStore);
	const { userInfo } = storeToRefs(userInfoStore);

	// 是否是管理员
	const isAdmin = computed(() => {
		return userInfo.value.roles.includes('admin') || userInfo.value.roles.includes('ald');
	})

	// 是否是置业顾问
	const isAdviser = computed(() => {
		return userInfo.value.roles.includes('kfs');
	})

	const props = defineProps({
		sellerStatus: {
			type: [String, Number],
			default: ''
		},
		check: {
			type: Boolean,
			default: false
		}
	})

	//数据采集
	function toStatisticsForm() {
		// uni.$u.toast('敬请期待')
		uni.navigateTo({
			url: `/pages/my/statistics/form/index`
		})
	}

	//数据统计
	function toStatisticsPage() {
		// uni.$u.toast('敬请期待')
		uni.navigateTo({
			url: `/pages/my/statistics/table/index`
		})
	}

	//置业顾问入驻
	function adviserJoin() {
		switch(props.sellerStatus) {
			case 1:
				uni.navigateTo({
					url: `/pages/my/adviser/detail?adviserId=${adviserId.value}&productId=${this.product.id}&puid=${this.puid}&title=${this.product.title}`
				})
				break;
			case 3:
				uni.navigateTo({
					url: "/pages/my/adviser/adviser-join"
				})
				break;
			default:
				uni.navigateTo({
					url: "/pages/my/adviser/adviser-status"
				})
		}
	}

	//推送
	async function pushHouseChange(e) {
		try{
			const {status, detail} = await pushHouseMsg('post');
			uni.$u.toast(status !== 0 ? detail : '设置成功');
			props.check = e.detail.value;
		}catch(error){
			console.log(error)
		}
	}

	//问题反馈
	function toFeedback(){
		if(!checkLogin()){
			uni.navigateTo({
				url: '/pages/login/login'
			})
		}
		if(!checkUserInfo()) {
			uni.navigateTo({
				url: `/pages/login/user-info-form`
			})
			return
		}
		uni.navigateTo({
			url: `/pages/my/feedback/index`
		})
	}

	//通用设置
	function toCurrency(){
		uni.navigateTo({
			url: '/pages/my/setting/page'
		})
	}

	//用户隐私协议和政策
	function toAgreement() {
		openAgreement()
	}

	//用户隐私协议和政策
	function toPolicy() {
		openPolicy()
	}
</script>

<style lang="scss" scoped>
.component{
	.listItem{
		border-bottom: 1rpx solid rgba(0,0,0,.04);
		height: 90rpx;
		padding: 0rpx 20rpx;
		justify-content: space-between;
		&:last-child{
			border: none;
		}
		.navTitle{
			justify-content: flex-start;
			.imgBox{
				width: 38rpx;
				height: 38rpx;
			}
			.myIcon{
				margin-right: 15rpx;
			}
		}
	}
	.pushHouseBox{
		padding: 0rpx 0rpx 0rpx 20rpx;
	}
}
</style>
